package terra.model;


import org.newdawn.slick.Color;
import org.newdawn.slick.geom.Circle;

import terra.Config;

/**
 * A single light in the example. It's capable of determining how much effect
 * it will have in any given point on the tile map. Note that all coordinates
 * are given in tile coordinates rather than pixel coordinates.
 * 
 * @author kevin
 */
public class Light extends Circle {

	private static final long serialVersionUID = -7658649768060098089L;
	private Color col;
	public GameObject owner;
	float[] floats = new float[3];
    public Light(Color col, float centerPointX, float centerPointY, float radius) {
        super(centerPointX, centerPointY, radius * Config.tileSize);
        this.col = col;
    }
    
    public float[] getEffectAtCorner(float x,float y, boolean colouredLights) {
        float dx = (x - getCenterX());
        float dy = (y - getCenterY());
        float distance2 = (dx * dx) + (dy * dy);
        float r = radius;
        float effect = 1f - (distance2 / (r * r));

        if (effect < 0) {
            effect = 0;
        }

        if (colouredLights) {
        	floats[0] = col.r * effect * col.a;
        	floats[1] = col.g * effect * col.a;
        	floats[2] = col.b * effect * col.a;
        	return floats;
            //return floats[]{col.r * effect * col.a, col.g * effect * col.a, col.b * effect * col.a};
        } else {
        	floats[0] = col.r * col.a;
        	floats[1] = col.g * col.a;
        	floats[2] = col.b * col.a;
        	return floats;
           // return new float[]{effect * col.a, effect * col.a, effect * col.a};
        }
    }
}
